PATH Variable on Windows, macOS, and Linux
This guide shows how to set the PATH environment variable on each OS, including
temporary (current terminal only) and permanent methods.
C:\Program Files\MyApp\binUser Path affects only your account. System Path affects all users and typically requires administrator privileges.
Command Prompt (cmd.exe):
set PATH=C:\MyApp\bin;%PATH%
PowerShell:
$env:PATH = "C:\MyApp\bin;$env:PATH"
Edit your zsh config:
nano ~/.zshrc
Add this line:
export PATH="/usr/local/myapp/bin:$PATH"
Apply immediately:
source ~/.zshrc
GUI apps sometimes don’t read shell config files. If a GUI app can’t find your command,
you may need to set PATH using launchctl and log out/in afterward:
launchctl setenv PATH "/usr/local/myapp/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export PATH="/usr/local/myapp/bin:$PATH"
Edit one of these files (depending on your shell/distro):
~/.bashrc
~/.bash_profile
~/.profile
~/.zshrc
Add:
export PATH="$HOME/myapp/bin:$PATH"
Apply:
source ~/.bashrc
Edit one of these (requires sudo):
sudo nano /etc/profile
or
sudo nano /etc/environment
Example (in /etc/environment):
PATH="/usr/local/myapp/bin:/usr/bin:/bin"
System-wide changes often require a logout/login (or reboot) to fully apply.
export PATH="$HOME/myapp/bin:$PATH"
macOS / Linux:
echo $PATH
which mycommand
Windows:
where mycommand
PATH instead of prepending/appending to it.bashrc vs .profile vs .zshrc)PATH| OS | Best Permanent Method | Temporary Method |
|---|---|---|
| Windows | User Environment Variables (Path) | set PATH=...;%PATH% or $env:PATH=... |
| macOS | ~/.zshrc |
export PATH="...:$PATH" |
| Linux | ~/.bashrc or ~/.profile |
export PATH="...:$PATH" |